﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using Lswweb.Domain;

namespace Lswweb.Controls
{
    public class UserSetAdmin : SkinnedWebControl
    {
        private TextBox tbxUserName;
        private Button btnAdd;
        private Button btnRemove;

        protected override void InitializeSkin(System.Web.UI.Control skin)
        {
            tbxUserName = (TextBox)skin.FindControl("tbxUserName");
            btnAdd = (Button)skin.FindControl("btnAdd");
            btnRemove = (Button)skin.FindControl("btnRemove");

            btnAdd.Click += new EventHandler(btnAdd_Click);
            btnRemove.Click += new EventHandler(btnRemove_Click);
        }

        void btnRemove_Click(object sender, EventArgs e)
        {
            Users.SetUserIsAdmin(UserName, false);
        }

        void btnAdd_Click(object sender, EventArgs e)
        {
            Users.SetUserIsAdmin(UserName, true);
        }

        private string UserName
        {
            get 
            {
                EnsureChildControls();
                if (tbxUserName != null)
                    return tbxUserName.Text.Trim();
                else
                    return string.Empty;
            }
        }

        protected override string DefaultSkinFilename
        {
            get { return "User/UserSetAdmin.ascx"; }
        }
    }
}
